/*
 *  Licensed to PECATS under one or more contributor license agreements below:
 *  1. http://www.mozilla.org/MPL/MPL-1.1.html
 *  2. http://www.gnu.org/licenses/gpl-2.0.html
 *  3. http://www.gnu.org/licenses/lgpl-2.1.html
*/

/* **********************************************************
*  Class to Store data of the log file access.log
*  Name: HitsData.java
*  Author: www.pecats.com
*  Date: Sep 15, 2008
************************************************************/

package com.pecats.batch.data;

import java.util.ArrayList;

/**
 * Used to store data about urlwise, hourwise, yearwise url summary
 */

public class HitsData
{

	int[] [] [] hits;     		// Three dimensional array to store data of hits in the format of URL KEY (number) * days(number) * hours(number)
	
	int[] []  hourhits;   		// Two dimensional array to store data of hits in the format of - hours(number) * URL KEY (number)
	int[] []  dayhits;     		// Two dimensional array to store data of hits in the format of - days(number) * URL KEY (number)
	int[] []  monthhits;  		// Two dimensional array to store data of hits in the format of - month(number) * URL KEY (number)	
	int[] []  yearhits;    		// Two dimensional array to store data of hits in the format of - year(number) * URL KEY (number)
	int[] browserData;		// One dimensional array to store data of browsers in the format of - browser(number) 

	ArrayList urlNames;    		// ArrayList to store URL's - Key is numbers and value is the URL (stored as a string)
	ArrayList statusCodes;  	// ArrayList to store statusCodes - Key is numbers and value is the statusCode (stored as a integer)
	ArrayList days;        		// ArrayList to store days of data being processed - Key is numbers and value is the Days(stored as a string)
	ArrayList months;        	// ArrayList to store months of data being processed - Key is numbers and value is the Months(stored as a string)
	ArrayList years;        	// ArrayList to store years of data being processed - Key is numbers and value is the Year(stored as a Number)
	ArrayList browsers;		// ArrayList to store data of browsers being processed - Key is numbers and value is the Browser (Stored as String)

	
	int [] [] statusCodesData; 	// Two dimensional array to store data of URL Key (number) and number of hits for each status code

	int urlNumber=0;
	int statusCodeNumber=0;
	int dayNumber=0;
	int monthNumber=0;
	int yearNumber=0;
	int browserNumber=0;

	// Constructor to initialize data being stored
	public HitsData()
	{
		hits = new int [100][100][24] ;

		hourhits = new int[24][100];
		dayhits = new int[365][100];
		monthhits = new int[24][100];
		yearhits = new int[2][100];
		browserData = new int[100];
		statusCodesData = new int[100][25];			

		urlNames = new ArrayList();
		days = new ArrayList();
		months = new ArrayList();
		years = new ArrayList();
		browsers = new ArrayList();
		statusCodes = new ArrayList();
	}


	public void setUrlName(int urlNumber, String urlName)
	{
		urlNames.add(urlNumber, urlName);
	}

	public Object getUrlName(int urlNumber)
	{
		return(urlNames.get(urlNumber));	
	}


	// Hour Methods
	
	public void setHourHitsData(String urlName, int hour)
	{
		urlNumber=urlNames.indexOf(urlName);
		hourhits[hour][urlNumber]++;
	}

	public int getHourHitsData(String urlName, int hour)
	{
		urlNumber=urlNames.indexOf(urlName);
		return(hourhits[hour][urlNumber]);
	}
	
	// Days Mehtods
	public void setDays(int dayNumber, String dayName)
	{
		days.add(dayNumber, dayName);
	}

	public Object getDays(int dayNumber)
	{
		return(days.get(dayNumber));	
	}

	public int getSizeDays()
	{
		return(days.size());
	}

	public int getDaysIndex(String dayName)
	{
		return(days.indexOf(dayName));	
	}

	public void setDayHitsData(String urlName, String dayName)
	{
		urlNumber=urlNames.indexOf(urlName);
		dayNumber=days.indexOf(dayName);
		dayhits[dayNumber][urlNumber]++;
	}

	public int getDayHitsData(String urlName, String dayName)
	{
		urlNumber=urlNames.indexOf(urlName);
		dayNumber=days.indexOf(dayName);
		return(dayhits[dayNumber][urlNumber]);
	}


	// Months Mehtods
	public void setMonths(int monthNumber, String monthName)
	{
		months.add(monthNumber, monthName);
	}

	public Object getMonths(int monthNumber)
	{
		return(months.get(monthNumber));	
	}

	public int getSizeMonths()
	{
		return(months.size());
	}

	public int getMonthsIndex(String monthsName)
	{
		return(months.indexOf(monthsName));	
	}

	public void setMonthHitsData(String urlName, String monthName)
	{
		urlNumber=urlNames.indexOf(urlName);
		monthNumber=months.indexOf(monthName);
		monthhits[monthNumber][urlNumber]++;
	}

	public int getMonthHitsData(String urlName, String monthName)
	{
		urlNumber=urlNames.indexOf(urlName);
		monthNumber=months.indexOf(monthName);
		return(monthhits[monthNumber][urlNumber]);
	}


	// Years Mehtods
	public void setYears(int yearNumber, int yearName)
	{
		years.add(yearNumber, yearName);
	}

	public Object getYears(int yearNumber)
	{
		return(years.get(yearNumber));	
	}

	public int getSizeYears()
	{
		return(years.size());
	}

	public int getYearsIndex(int yearName)
	{
		return(years.indexOf(yearName));	
	}

	public void setYearHitsData(String urlName, int yearName)
	{
		urlNumber=urlNames.indexOf(urlName);
		yearNumber=years.indexOf(yearName);
		yearhits[yearNumber][urlNumber]++;
	}

	public int getYearHitsData(String urlName, int yearName)
	{
		urlNumber=urlNames.indexOf(urlName);
		yearNumber=years.indexOf(yearName);
		return(yearhits[yearNumber][urlNumber]);
	}

	public int getSizeUrlName()
	{
		return(urlNames.size());
	}

	public int getUrlIndex(String urlName)
	{
		return(urlNames.indexOf(urlName));	
	}


	// Status Codes Data
	public void setStatusCodes(int urlNumber, int StatusCodes)
	{
		statusCodes.add(urlNumber, StatusCodes);
	}

	public Object getStatusCodes(int urlNumber)
	{
		return(statusCodes.get(urlNumber));	
	}

	public int getSizeStatusCodes()
	{
		return(statusCodes.size());
	}

	public int getStatusCodesIndex(int statusCode)
	{
		return(statusCodes.indexOf(statusCode));	
	}

	public void setStatusCodesData(String urlName, int StatusCode)
	{
		urlNumber=urlNames.indexOf(urlName);
		statusCodeNumber = statusCodes.indexOf(StatusCode);
		statusCodesData[urlNumber][statusCodeNumber]++;
	}

	public int getStatusCodesData(String urlName, int StatusCode)
	{
		urlNumber=urlNames.indexOf(urlName);
		statusCodeNumber = statusCodes.indexOf(StatusCode);
		return(statusCodesData[urlNumber][statusCodeNumber]);	
	}

	// Browser Data
	public void setBrowsers(int browserNumber, String browser)
	{
		browsers.add(browserNumber, browser);
	}

	public Object getBrowsers(int browserNumber)
	{
		return(browsers.get(browserNumber));	
	}

	public int getSizeBrowsers()
	{
		return(browsers.size());
	}

	public int getBrowsersIndex(String browser)
	{
		return(browsers.indexOf(browser));	
	}

	public void setBrowsersData(String browser)
	{
		browserNumber = browsers.indexOf(browser);
		browserData[browserNumber]++;
	}

	public int getBrowsersData(String browser)
	{
		browserNumber = browsers.indexOf(browser);
		return(browserData[browserNumber]);	
	}

	// Hits Data

	public void setHitsData(String urlName, String day, int hour)
	{
		urlNumber=urlNames.indexOf(urlName);
		dayNumber=days.indexOf(day);
		hits[urlNumber][dayNumber][hour]++;
	}

	public int getHitsData(String urlName, String day, int hour)
	{
		urlNumber=urlNames.indexOf(urlName);
		dayNumber=days.indexOf(day);
		return(hits[urlNumber][dayNumber][hour]);
	}
		

}